package com.gitee.qdbp.jdbc.support.convert;

import org.springframework.core.convert.converter.Converter;
import com.alibaba.fastjson.JSONObject;
import com.gitee.qdbp.able.jdbc.model.DbFieldValue;
import com.gitee.qdbp.jdbc.test.model.UserCoreOptions;

/**
 * UserCoreOptions转换为数据库保存对象
 *
 * @author zhaohuihua
 * @version 20210708
 */
public class UserCoreOptionsConverter {

    public static class ToDbValue implements Converter<UserCoreOptions, DbFieldValue> {

        @Override
        public DbFieldValue convert(UserCoreOptions source) {
            if (source == null) {
                return new DbFieldValue(null);
            } else {
                return new DbFieldValue(JSONObject.toJSONString(source));
            }
        }
    }

    public static class ParseString implements Converter<String, UserCoreOptions> {

        @Override
        public UserCoreOptions convert(String source) {
            return source == null ? null : JSONObject.parseObject(source, UserCoreOptions.class);
        }
    }
}
